﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Manage.Model;
using Newtonsoft.Json;

namespace Manage.Basic
{
    public partial class FrmPass : Form
    {
        public FrmPass()
        {
            InitializeComponent();
        }

        private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (tbxNewPass.Text.Trim() != tbxNewPass2.Text.Trim())
            {
                MessageBox.Show("两次密码输入不相同！请重新输入");
                tbxNewPass2.Text = "";
                tbxNewPass.Text = "";
                tbxNewPass.Focus();
            }
            else
            {
                Dictionary<string, string> dc = new Dictionary<string, string>();
                dc.Add("Token", Share.MoM.Token);
                dc.Add("OldPass", CryptUtil.Crypt.MD32Crypt(tbxOldPass.Text.Trim()));
                ManagerModel mm = new ManagerModel();
                mm.MPassWord = CryptUtil.Crypt.MD32Crypt(tbxNewPass.Text.Trim());
                mm.id = Share.MoM.id;
                RetModel ret = Share.PostData("51API/Manage/PassEdit", dc, JsonConvert.SerializeObject(mm));
                if(ret.Success)
                {
                    MessageBox.Show("密码修改成功！");
                    tbxOldPass.Text = "";
                    tbxNewPass.Text = "";
                    tbxNewPass2.Text = "";
                }
                else
                {
                    MessageBox.Show("修改密码失败" + ret.ErrInfo);
                    tbxOldPass.Text = "";
                    tbxNewPass.Text = "";
                    tbxNewPass2.Text = "";
                }
            }
            
            

        }

        private void barButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Dispose();
        }
    }
}
